<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Cheetah Software: PeriodicTask.cpp Source File</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Cheetah Software
   &#160;<span id="projectnumber">1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="../../index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="../../namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="../../annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="../../files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="../../search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="../../search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="../../files.html"><span>File&#160;List</span></a></li>
      <li><a href="../../globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('de/df7/_periodic_task_8cpp_source.html','../../');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">PeriodicTask.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="../../de/df7/_periodic_task_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="../../dc/d87/_periodic_task_8h.html">include/Utilities/PeriodicTask.h</a>&quot;</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="../../d5/d29/_timer_8h.html">include/Utilities/Timer.h</a>&gt;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &lt;sys/timerfd.h&gt;</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;cmath&gt;</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="../../d3/d68/_utilities__print_8h.html">Utilities/Utilities_print.h</a>&quot;</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;</div><div class="line"><a name="l00014"></a><span class="lineno"><a class="line" href="../../de/d2f/class_periodic_task.html#aadb0c519e5d15feae5e66cdecaeb54f6">   14</a></span>&#160;<a class="code" href="../../de/d2f/class_periodic_task.html#aadb0c519e5d15feae5e66cdecaeb54f6">PeriodicTask::PeriodicTask</a>(<a class="code" href="../../d2/d31/class_periodic_task_manager.html">PeriodicTaskManager</a>* taskManager, <span class="keywordtype">float</span> period,</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;                           std::string name)</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;    : _period(period), _name(name) {</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;  taskManager-&gt;<a class="code" href="../../d2/d31/class_periodic_task_manager.html#aa50992596d26d9ac9b9c741015d990d2">addTask</a>(<span class="keyword">this</span>);</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;}</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno"><a class="line" href="../../de/d2f/class_periodic_task.html#a23a65ac2dff9750a0f0d6416f2f32a6f">   20</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../de/d2f/class_periodic_task.html#a23a65ac2dff9750a0f0d6416f2f32a6f">PeriodicTask::start</a>() {</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="../../de/d2f/class_periodic_task.html#a285fb43831f136ac3dce9566b4b50a8d">_running</a>) {</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;    printf(<span class="stringliteral">&quot;[PeriodicTask] Tried to start %s but it was already running!\n&quot;</span>,</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;           <a class="code" href="../../de/d2f/class_periodic_task.html#a18972d9e1945410256791965f3730dae">_name</a>.c_str());</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;    <span class="keywordflow">return</span>;</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;  }</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;  <a class="code" href="../../de/d2f/class_periodic_task.html#a8bc384b67a67e01b29afc0362732204d">init</a>();</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;  <a class="code" href="../../de/d2f/class_periodic_task.html#a285fb43831f136ac3dce9566b4b50a8d">_running</a> = <span class="keyword">true</span>;</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;  <a class="code" href="../../de/d2f/class_periodic_task.html#aa7928c99eb0134cf58398c7eb885c41c">_thread</a> = std::thread(&amp;<a class="code" href="../../de/d2f/class_periodic_task.html#a749e849501c8369723c1b7822c5a2dc5">PeriodicTask::loopFunction</a>, <span class="keyword">this</span>);</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;}</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div><div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="../../de/d2f/class_periodic_task.html#ad24498c03bd938845244546d52dfa24b">   31</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../de/d2f/class_periodic_task.html#ad24498c03bd938845244546d52dfa24b">PeriodicTask::stop</a>() {</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="../../de/d2f/class_periodic_task.html#a285fb43831f136ac3dce9566b4b50a8d">_running</a>) {</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;    printf(<span class="stringliteral">&quot;[PeriodicTask] Tried to stop %s but it wasn&#39;t running!\n&quot;</span>,</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;           <a class="code" href="../../de/d2f/class_periodic_task.html#a18972d9e1945410256791965f3730dae">_name</a>.c_str());</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    <span class="keywordflow">return</span>;</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;  }</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;  <a class="code" href="../../de/d2f/class_periodic_task.html#a285fb43831f136ac3dce9566b4b50a8d">_running</a> = <span class="keyword">false</span>;</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;  printf(<span class="stringliteral">&quot;[PeriodicTask] Waiting for %s to stop...\n&quot;</span>, <a class="code" href="../../de/d2f/class_periodic_task.html#a18972d9e1945410256791965f3730dae">_name</a>.c_str());</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;  <a class="code" href="../../de/d2f/class_periodic_task.html#aa7928c99eb0134cf58398c7eb885c41c">_thread</a>.join();</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;  printf(<span class="stringliteral">&quot;[PeriodicTask] Done!\n&quot;</span>);</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;  <a class="code" href="../../de/d2f/class_periodic_task.html#a5b4d756df249cf8adda268d509390ef4">cleanup</a>();</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;}</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;</div><div class="line"><a name="l00044"></a><span class="lineno"><a class="line" href="../../de/d2f/class_periodic_task.html#ad6928f8428ae4944314011aee9fd4764">   44</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="../../de/d2f/class_periodic_task.html#ad6928f8428ae4944314011aee9fd4764">PeriodicTask::isSlow</a>() {</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="../../de/d2f/class_periodic_task.html#ae613597442fa17fcbf362de31ce61920">_maxPeriod</a> &gt; <a class="code" href="../../de/d2f/class_periodic_task.html#af395b5169de444767ae3b0ccd6175942">_period</a> * 1.3f || <a class="code" href="../../de/d2f/class_periodic_task.html#afa649a810c363bc0567336e663868421">_maxRuntime</a> &gt; <a class="code" href="../../de/d2f/class_periodic_task.html#af395b5169de444767ae3b0ccd6175942">_period</a>;</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;}</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;</div><div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="../../de/d2f/class_periodic_task.html#a90827dff3d3383036747c5d2557693f8">   48</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../de/d2f/class_periodic_task.html#a90827dff3d3383036747c5d2557693f8">PeriodicTask::clearMax</a>() {</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;  <a class="code" href="../../de/d2f/class_periodic_task.html#ae613597442fa17fcbf362de31ce61920">_maxPeriod</a> = 0;</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;  <a class="code" href="../../de/d2f/class_periodic_task.html#afa649a810c363bc0567336e663868421">_maxRuntime</a> = 0;</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;}</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno"><a class="line" href="../../de/d2f/class_periodic_task.html#ab9031986941baaf7183f4d24bc861110">   53</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../de/d2f/class_periodic_task.html#ab9031986941baaf7183f4d24bc861110">PeriodicTask::printStatus</a>() {</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="../../de/d2f/class_periodic_task.html#a285fb43831f136ac3dce9566b4b50a8d">_running</a>) <span class="keywordflow">return</span>;</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="../../de/d2f/class_periodic_task.html#ad6928f8428ae4944314011aee9fd4764">isSlow</a>()) {</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <a class="code" href="../../d3/d68/_utilities__print_8h.html#a2b2d015520d3b5e1562e8d70609a2b63">printf_color</a>(<a class="code" href="../../d3/d68/_utilities__print_8h.html#a77255dc095356f8499023fbd092cd835aee38e4d5dd68c4e440825018d549cb47">PrintColor::Red</a>, <span class="stringliteral">&quot;|%-20s|%6.4f|%6.4f|%6.4f|%6.4f|%6.4f\n&quot;</span>,</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;                 <a class="code" href="../../de/d2f/class_periodic_task.html#a18972d9e1945410256791965f3730dae">_name</a>.c_str(), <a class="code" href="../../de/d2f/class_periodic_task.html#ae3788f2b05fc248745ee93f41da24c8f">_lastRuntime</a>, <a class="code" href="../../de/d2f/class_periodic_task.html#afa649a810c363bc0567336e663868421">_maxRuntime</a>, <a class="code" href="../../de/d2f/class_periodic_task.html#af395b5169de444767ae3b0ccd6175942">_period</a>,</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;                 <a class="code" href="../../de/d2f/class_periodic_task.html#a5e68d6cc68240995a142b8825b8df174">_lastPeriodTime</a>, <a class="code" href="../../de/d2f/class_periodic_task.html#ae613597442fa17fcbf362de31ce61920">_maxPeriod</a>);</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    printf(<span class="stringliteral">&quot;|%-20s|%6.4f|%6.4f|%6.4f|%6.4f|%6.4f\n&quot;</span>, <a class="code" href="../../de/d2f/class_periodic_task.html#a18972d9e1945410256791965f3730dae">_name</a>.c_str(),</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;           <a class="code" href="../../de/d2f/class_periodic_task.html#ae3788f2b05fc248745ee93f41da24c8f">_lastRuntime</a>, <a class="code" href="../../de/d2f/class_periodic_task.html#afa649a810c363bc0567336e663868421">_maxRuntime</a>, <a class="code" href="../../de/d2f/class_periodic_task.html#af395b5169de444767ae3b0ccd6175942">_period</a>, <a class="code" href="../../de/d2f/class_periodic_task.html#a5e68d6cc68240995a142b8825b8df174">_lastPeriodTime</a>, <a class="code" href="../../de/d2f/class_periodic_task.html#ae613597442fa17fcbf362de31ce61920">_maxPeriod</a>);</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;  }</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;}</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;</div><div class="line"><a name="l00065"></a><span class="lineno"><a class="line" href="../../de/d2f/class_periodic_task.html#a749e849501c8369723c1b7822c5a2dc5">   65</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../de/d2f/class_periodic_task.html#a749e849501c8369723c1b7822c5a2dc5">PeriodicTask::loopFunction</a>() {</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;  <span class="keyword">auto</span> timerFd = timerfd_create(CLOCK_MONOTONIC, 0);</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;  <span class="keywordtype">int</span> seconds = (int)<a class="code" href="../../de/d2f/class_periodic_task.html#af395b5169de444767ae3b0ccd6175942">_period</a>;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  <span class="keywordtype">int</span> nanoseconds = (int)(1e9 * std::fmod(<a class="code" href="../../de/d2f/class_periodic_task.html#af395b5169de444767ae3b0ccd6175942">_period</a>, 1.<a class="code" href="../../dc/dd7/test__casadi_8cpp.html#ae20d7fba59865a21504b65cdb44cbfe5">f</a>));</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;  <a class="code" href="../../d8/d08/class_timer.html">Timer</a> t;</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;  itimerspec timerSpec;</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;  timerSpec.it_interval.tv_sec = seconds;</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;  timerSpec.it_value.tv_sec = seconds;</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;  timerSpec.it_value.tv_nsec = nanoseconds;</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;  timerSpec.it_interval.tv_nsec = nanoseconds;</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;  timerfd_settime(timerFd, 0, &amp;timerSpec, <span class="keyword">nullptr</span>);</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span> missed = 0;</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;  printf(<span class="stringliteral">&quot;[PeriodicTask] Start %s (%d s, %d ns)\n&quot;</span>, <a class="code" href="../../de/d2f/class_periodic_task.html#a18972d9e1945410256791965f3730dae">_name</a>.c_str(), seconds,</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;         nanoseconds);</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;  <span class="keywordflow">while</span> (<a class="code" href="../../de/d2f/class_periodic_task.html#a285fb43831f136ac3dce9566b4b50a8d">_running</a>) {</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    <a class="code" href="../../de/d2f/class_periodic_task.html#a5e68d6cc68240995a142b8825b8df174">_lastPeriodTime</a> = (float)t.<a class="code" href="../../d8/d08/class_timer.html#aa42cb0519d30540b49a8c73f8ea81470">getSeconds</a>();</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    t.<a class="code" href="../../d8/d08/class_timer.html#a3a8b5272198d029779dc9302a54305a8">start</a>();</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    <a class="code" href="../../de/d2f/class_periodic_task.html#ae6976f44c995555b6403b38443fb2eb5">run</a>();</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;    <a class="code" href="../../de/d2f/class_periodic_task.html#ae3788f2b05fc248745ee93f41da24c8f">_lastRuntime</a> = (float)t.<a class="code" href="../../d8/d08/class_timer.html#aa42cb0519d30540b49a8c73f8ea81470">getSeconds</a>();</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    <span class="keywordtype">int</span> m = read(timerFd, &amp;missed, <span class="keyword">sizeof</span>(missed));</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    (void)m;</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    <a class="code" href="../../de/d2f/class_periodic_task.html#ae613597442fa17fcbf362de31ce61920">_maxPeriod</a> = std::max(<a class="code" href="../../de/d2f/class_periodic_task.html#ae613597442fa17fcbf362de31ce61920">_maxPeriod</a>, <a class="code" href="../../de/d2f/class_periodic_task.html#a5e68d6cc68240995a142b8825b8df174">_lastPeriodTime</a>);</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    <a class="code" href="../../de/d2f/class_periodic_task.html#afa649a810c363bc0567336e663868421">_maxRuntime</a> = std::max(<a class="code" href="../../de/d2f/class_periodic_task.html#afa649a810c363bc0567336e663868421">_maxRuntime</a>, <a class="code" href="../../de/d2f/class_periodic_task.html#ae3788f2b05fc248745ee93f41da24c8f">_lastRuntime</a>);</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;  }</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;  printf(<span class="stringliteral">&quot;[PeriodicTask] %s has stopped!\n&quot;</span>, <a class="code" href="../../de/d2f/class_periodic_task.html#a18972d9e1945410256791965f3730dae">_name</a>.c_str());</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;}</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;</div><div class="line"><a name="l00096"></a><span class="lineno"><a class="line" href="../../d2/d31/class_periodic_task_manager.html#ae4480084f4d94a8a3a282d1274fadc1e">   96</a></span>&#160;<a class="code" href="../../d2/d31/class_periodic_task_manager.html#ae4480084f4d94a8a3a282d1274fadc1e">PeriodicTaskManager::~PeriodicTaskManager</a>() {}</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;</div><div class="line"><a name="l00098"></a><span class="lineno"><a class="line" href="../../d2/d31/class_periodic_task_manager.html#aa50992596d26d9ac9b9c741015d990d2">   98</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../d2/d31/class_periodic_task_manager.html#aa50992596d26d9ac9b9c741015d990d2">PeriodicTaskManager::addTask</a>(<a class="code" href="../../de/d2f/class_periodic_task.html">PeriodicTask</a>* task) {</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;  _tasks.push_back(task);</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;}</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;</div><div class="line"><a name="l00102"></a><span class="lineno"><a class="line" href="../../d2/d31/class_periodic_task_manager.html#abfcbfd0777e7f1b9f2f01ce1f8cc0b62">  102</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../d2/d31/class_periodic_task_manager.html#abfcbfd0777e7f1b9f2f01ce1f8cc0b62">PeriodicTaskManager::printStatus</a>() {</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;  printf(<span class="stringliteral">&quot;\n----------------------------TASKS----------------------------\n&quot;</span>);</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;  printf(<span class="stringliteral">&quot;|%-20s|%-6s|%-6s|%-6s|%-6s|%-6s\n&quot;</span>, <span class="stringliteral">&quot;name&quot;</span>, <span class="stringliteral">&quot;rt&quot;</span>, <span class="stringliteral">&quot;rt-max&quot;</span>, <span class="stringliteral">&quot;T-des&quot;</span>,</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;         <span class="stringliteral">&quot;T-act&quot;</span>, <span class="stringliteral">&quot;T-max&quot;</span>);</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;  printf(<span class="stringliteral">&quot;-----------------------------------------------------------\n&quot;</span>);</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;  <span class="keywordflow">for</span> (<span class="keyword">auto</span>&amp; task : _tasks) {</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    task-&gt;printStatus();</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;    task-&gt;clearMax();</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;  }</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;  printf(<span class="stringliteral">&quot;-------------------------------------------------------------\n\n&quot;</span>);</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;}</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;</div><div class="line"><a name="l00114"></a><span class="lineno"><a class="line" href="../../d2/d31/class_periodic_task_manager.html#afacfb819a01174d05d0c77f8140ac385">  114</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../d2/d31/class_periodic_task_manager.html#afacfb819a01174d05d0c77f8140ac385">PeriodicTaskManager::printStatusOfSlowTasks</a>() {</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;  <span class="keywordflow">for</span> (<span class="keyword">auto</span>&amp; task : _tasks) {</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    <span class="keywordflow">if</span> (task-&gt;isSlow()) {</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;      task-&gt;printStatus();</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;      task-&gt;clearMax();</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    }</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;  }</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;}</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;</div><div class="line"><a name="l00123"></a><span class="lineno"><a class="line" href="../../d2/d31/class_periodic_task_manager.html#ac3a6d2e72967f7e1045b546fdb5d7eaa">  123</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../d2/d31/class_periodic_task_manager.html#ac3a6d2e72967f7e1045b546fdb5d7eaa">PeriodicTaskManager::stopAll</a>() {</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;  <span class="keywordflow">for</span> (<span class="keyword">auto</span>&amp; task : _tasks) {</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;    task-&gt;stop();</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;  }</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;}</div><div class="ttc" id="class_periodic_task_html_ae3788f2b05fc248745ee93f41da24c8f"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#ae3788f2b05fc248745ee93f41da24c8f">PeriodicTask::_lastRuntime</a></div><div class="ttdeci">float _lastRuntime</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00046">PeriodicTask.h:46</a></div></div>
<div class="ttc" id="class_timer_html"><div class="ttname"><a href="../../d8/d08/class_timer.html">Timer</a></div><div class="ttdef"><b>Definition:</b> <a href="../../d5/d29/_timer_8h_source.html#l00012">Timer.h:12</a></div></div>
<div class="ttc" id="class_periodic_task_html_ad6928f8428ae4944314011aee9fd4764"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#ad6928f8428ae4944314011aee9fd4764">PeriodicTask::isSlow</a></div><div class="ttdeci">bool isSlow()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00044">PeriodicTask.cpp:44</a></div></div>
<div class="ttc" id="class_periodic_task_html_a90827dff3d3383036747c5d2557693f8"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#a90827dff3d3383036747c5d2557693f8">PeriodicTask::clearMax</a></div><div class="ttdeci">void clearMax()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00048">PeriodicTask.cpp:48</a></div></div>
<div class="ttc" id="_periodic_task_8h_html"><div class="ttname"><a href="../../dc/d87/_periodic_task_8h.html">PeriodicTask.h</a></div><div class="ttdoc">Implementation of a periodic function running in a separate thread. Periodic tasks have a task manage...</div></div>
<div class="ttc" id="class_periodic_task_html_aadb0c519e5d15feae5e66cdecaeb54f6"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#aadb0c519e5d15feae5e66cdecaeb54f6">PeriodicTask::PeriodicTask</a></div><div class="ttdeci">PeriodicTask(PeriodicTaskManager *taskManager, float period, std::string name)</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00014">PeriodicTask.cpp:14</a></div></div>
<div class="ttc" id="class_timer_html_a3a8b5272198d029779dc9302a54305a8"><div class="ttname"><a href="../../d8/d08/class_timer.html#a3a8b5272198d029779dc9302a54305a8">Timer::start</a></div><div class="ttdeci">void start()</div><div class="ttdef"><b>Definition:</b> <a href="../../d5/d29/_timer_8h_source.html#l00016">Timer.h:16</a></div></div>
<div class="ttc" id="class_periodic_task_html_a749e849501c8369723c1b7822c5a2dc5"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#a749e849501c8369723c1b7822c5a2dc5">PeriodicTask::loopFunction</a></div><div class="ttdeci">void loopFunction()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00065">PeriodicTask.cpp:65</a></div></div>
<div class="ttc" id="_utilities__print_8h_html_a77255dc095356f8499023fbd092cd835aee38e4d5dd68c4e440825018d549cb47"><div class="ttname"><a href="../../d3/d68/_utilities__print_8h.html#a77255dc095356f8499023fbd092cd835aee38e4d5dd68c4e440825018d549cb47">PrintColor::Red</a></div></div>
<div class="ttc" id="_utilities__print_8h_html"><div class="ttname"><a href="../../d3/d68/_utilities__print_8h.html">Utilities_print.h</a></div></div>
<div class="ttc" id="class_periodic_task_html"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html">PeriodicTask</a></div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00019">PeriodicTask.h:19</a></div></div>
<div class="ttc" id="class_periodic_task_html_a285fb43831f136ac3dce9566b4b50a8d"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#a285fb43831f136ac3dce9566b4b50a8d">PeriodicTask::_running</a></div><div class="ttdeci">volatile bool _running</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00045">PeriodicTask.h:45</a></div></div>
<div class="ttc" id="class_periodic_task_html_ad24498c03bd938845244546d52dfa24b"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#ad24498c03bd938845244546d52dfa24b">PeriodicTask::stop</a></div><div class="ttdeci">void stop()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00031">PeriodicTask.cpp:31</a></div></div>
<div class="ttc" id="class_periodic_task_html_a5e68d6cc68240995a142b8825b8df174"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#a5e68d6cc68240995a142b8825b8df174">PeriodicTask::_lastPeriodTime</a></div><div class="ttdeci">float _lastPeriodTime</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00047">PeriodicTask.h:47</a></div></div>
<div class="ttc" id="class_periodic_task_manager_html_ac3a6d2e72967f7e1045b546fdb5d7eaa"><div class="ttname"><a href="../../d2/d31/class_periodic_task_manager.html#ac3a6d2e72967f7e1045b546fdb5d7eaa">PeriodicTaskManager::stopAll</a></div><div class="ttdeci">void stopAll()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00123">PeriodicTask.cpp:123</a></div></div>
<div class="ttc" id="class_timer_html_aa42cb0519d30540b49a8c73f8ea81470"><div class="ttname"><a href="../../d8/d08/class_timer.html#aa42cb0519d30540b49a8c73f8ea81470">Timer::getSeconds</a></div><div class="ttdeci">double getSeconds()</div><div class="ttdef"><b>Definition:</b> <a href="../../d5/d29/_timer_8h_source.html#l00027">Timer.h:27</a></div></div>
<div class="ttc" id="_timer_8h_html"><div class="ttname"><a href="../../d5/d29/_timer_8h.html">Timer.h</a></div><div class="ttdoc">Timer for measuring how long things take. </div></div>
<div class="ttc" id="class_periodic_task_html_af395b5169de444767ae3b0ccd6175942"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#af395b5169de444767ae3b0ccd6175942">PeriodicTask::_period</a></div><div class="ttdeci">float _period</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00044">PeriodicTask.h:44</a></div></div>
<div class="ttc" id="class_periodic_task_manager_html_abfcbfd0777e7f1b9f2f01ce1f8cc0b62"><div class="ttname"><a href="../../d2/d31/class_periodic_task_manager.html#abfcbfd0777e7f1b9f2f01ce1f8cc0b62">PeriodicTaskManager::printStatus</a></div><div class="ttdeci">void printStatus()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00102">PeriodicTask.cpp:102</a></div></div>
<div class="ttc" id="class_periodic_task_html_ae613597442fa17fcbf362de31ce61920"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#ae613597442fa17fcbf362de31ce61920">PeriodicTask::_maxPeriod</a></div><div class="ttdeci">float _maxPeriod</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00048">PeriodicTask.h:48</a></div></div>
<div class="ttc" id="class_periodic_task_manager_html_ae4480084f4d94a8a3a282d1274fadc1e"><div class="ttname"><a href="../../d2/d31/class_periodic_task_manager.html#ae4480084f4d94a8a3a282d1274fadc1e">PeriodicTaskManager::~PeriodicTaskManager</a></div><div class="ttdeci">~PeriodicTaskManager()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00096">PeriodicTask.cpp:96</a></div></div>
<div class="ttc" id="class_periodic_task_manager_html_afacfb819a01174d05d0c77f8140ac385"><div class="ttname"><a href="../../d2/d31/class_periodic_task_manager.html#afacfb819a01174d05d0c77f8140ac385">PeriodicTaskManager::printStatusOfSlowTasks</a></div><div class="ttdeci">void printStatusOfSlowTasks()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00114">PeriodicTask.cpp:114</a></div></div>
<div class="ttc" id="class_periodic_task_html_a18972d9e1945410256791965f3730dae"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#a18972d9e1945410256791965f3730dae">PeriodicTask::_name</a></div><div class="ttdeci">std::string _name</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00050">PeriodicTask.h:50</a></div></div>
<div class="ttc" id="_utilities__print_8h_html_a2b2d015520d3b5e1562e8d70609a2b63"><div class="ttname"><a href="../../d3/d68/_utilities__print_8h.html#a2b2d015520d3b5e1562e8d70609a2b63">printf_color</a></div><div class="ttdeci">void printf_color(PrintColor color, const char *fmt,...)</div><div class="ttdef"><b>Definition:</b> <a href="../../d6/df9/_utilities__print_8cpp_source.html#l00003">Utilities_print.cpp:3</a></div></div>
<div class="ttc" id="class_periodic_task_html_a8bc384b67a67e01b29afc0362732204d"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#a8bc384b67a67e01b29afc0362732204d">PeriodicTask::init</a></div><div class="ttdeci">virtual void init()=0</div></div>
<div class="ttc" id="class_periodic_task_html_ae6976f44c995555b6403b38443fb2eb5"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#ae6976f44c995555b6403b38443fb2eb5">PeriodicTask::run</a></div><div class="ttdeci">virtual void run()=0</div></div>
<div class="ttc" id="class_periodic_task_html_afa649a810c363bc0567336e663868421"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#afa649a810c363bc0567336e663868421">PeriodicTask::_maxRuntime</a></div><div class="ttdeci">float _maxRuntime</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00049">PeriodicTask.h:49</a></div></div>
<div class="ttc" id="class_periodic_task_html_aa7928c99eb0134cf58398c7eb885c41c"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#aa7928c99eb0134cf58398c7eb885c41c">PeriodicTask::_thread</a></div><div class="ttdeci">std::thread _thread</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00051">PeriodicTask.h:51</a></div></div>
<div class="ttc" id="class_periodic_task_html_a23a65ac2dff9750a0f0d6416f2f32a6f"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#a23a65ac2dff9750a0f0d6416f2f32a6f">PeriodicTask::start</a></div><div class="ttdeci">void start()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00020">PeriodicTask.cpp:20</a></div></div>
<div class="ttc" id="class_periodic_task_html_a5b4d756df249cf8adda268d509390ef4"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#a5b4d756df249cf8adda268d509390ef4">PeriodicTask::cleanup</a></div><div class="ttdeci">virtual void cleanup()=0</div></div>
<div class="ttc" id="class_periodic_task_html_ab9031986941baaf7183f4d24bc861110"><div class="ttname"><a href="../../de/d2f/class_periodic_task.html#ab9031986941baaf7183f4d24bc861110">PeriodicTask::printStatus</a></div><div class="ttdeci">void printStatus()</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00053">PeriodicTask.cpp:53</a></div></div>
<div class="ttc" id="class_periodic_task_manager_html"><div class="ttname"><a href="../../d2/d31/class_periodic_task_manager.html">PeriodicTaskManager</a></div><div class="ttdef"><b>Definition:</b> <a href="../../dc/d87/_periodic_task_8h_source.html#l00057">PeriodicTask.h:57</a></div></div>
<div class="ttc" id="class_periodic_task_manager_html_aa50992596d26d9ac9b9c741015d990d2"><div class="ttname"><a href="../../d2/d31/class_periodic_task_manager.html#aa50992596d26d9ac9b9c741015d990d2">PeriodicTaskManager::addTask</a></div><div class="ttdeci">void addTask(PeriodicTask *task)</div><div class="ttdef"><b>Definition:</b> <a href="../../de/df7/_periodic_task_8cpp_source.html#l00098">PeriodicTask.cpp:98</a></div></div>
<div class="ttc" id="test__casadi_8cpp_html_ae20d7fba59865a21504b65cdb44cbfe5"><div class="ttname"><a href="../../dc/dd7/test__casadi_8cpp.html#ae20d7fba59865a21504b65cdb44cbfe5">f</a></div><div class="ttdeci">MX f(const MX &amp;x, const MX &amp;u)</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/dd7/test__casadi_8cpp_source.html#l00202">test_casadi.cpp:202</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="../../dir_43e0a1f539e00dcfa1a6bc4d4fee4fc2.html">home</a></li><li class="navelem"><a class="el" href="../../dir_61bfb0b3cdda81b1b0355ba34eb3b1eb.html">dhkim</a></li><li class="navelem"><a class="el" href="../../dir_adee5b101e079090017bb4e91c628ead.html">Public_Repository</a></li><li class="navelem"><a class="el" href="../../dir_7fc07a7b97001e7b1d18e11da761e2de.html">Cheetah-Software</a></li><li class="navelem"><a class="el" href="../../dir_860379c26524a894b3cf97b5b1ba5bdb.html">common</a></li><li class="navelem"><a class="el" href="../../dir_054bbb67b14bc4d9ad4b8f9fd2c17d22.html">src</a></li><li class="navelem"><a class="el" href="../../dir_a3305345559b124a2d958a1c8c1671aa.html">Utilities</a></li><li class="navelem"><a class="el" href="../../de/df7/_periodic_task_8cpp.html">PeriodicTask.cpp</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
